package top.hkyzf.study.leetcode.array;

/**
 * description: 
 * @author zhufeng
 * @date 2024/3/21 0021 12:25
 * @version V1.0
 */
public class FrequencyTracker {
    int[] freq = new int[100001];
    int[] freqCnt = new int[100001];
    public FrequencyTracker() {

    }

    public void add(int number) {
        --freqCnt[freq[number]];
        ++freq[number];
        ++freqCnt[freq[number]];
    }

    public void deleteOne(int number) {
        if (freq[number] == 0) {
            return;
        }
        --freqCnt[freq[number]];
        --freq[number];
        ++freqCnt[freq[number]];
    }

    public boolean hasFrequency(int frequency) {
        return freqCnt[frequency] > 0;
    }
}
